gc()
##          used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 468543 25.1    1005837 53.8   665714 35.6
## Vcells 875353  6.7    8388608 64.0  1819492 13.9
rm(list=ls())
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.1.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(reticulate)
library(ade4)
library(reticulate)
library(htmltools)
library('Ternary')
setwd(dir = "/scratch/anissa.el/ImmuneStates/")

Macrophages phenotypes

NBCELLTYPES = 17
CELLTYPES <- c('CD8-T', 'Other immune', 'DC / Mono', 'CD3-T', 'B', 'NK', 'Keratin-positive tumor', 'Tumor','CD4-T', 'Mesenchymal-like', 'Macrophages', 'Endothelial', 'Tregs', 'Unidentified', 'DC', 'Mono / Neu','Neutrophils')
MarkersCellsTMENS <- readRDS("./markers_cells_tmens.rds")
selectedMarkers <- readRDS("./selected_markers_cells.rds")

3D ternary plots

#### CD4-T
#,results = 'asis'
#CellTypes.toPlot <- unique(selectedMarkers[["cell_type"]])
library('IRdisplay')

Markers.toPlot <-selectedMarkers%>%filter(cell_type == "Macrophages")%>%pull(marker)
# PlotsList <- list()
# PlotsList <- lapply(Markers.toPlot, function(marker1){
#   fig <- plot_3D_ternary_cell_markers("CD4-T", marker1)
#   print(htmltools::tagList(fig))
#   #cat(as.character(htmltools::tagList(fig)))#,browse=TRUE
#   #htmlwidgets::saveWidget(fig,"fig1.html")
#   #htmltools::html_print(fig)
# })

plot_3D_ternary_cell_markers("Macrophages", Markers.toPlot[1])
    0%        10%        50%        80%        99% 

-0.0070565 -0.0070565 -0.0070565 -0.0070565 -0.0070565

## Warning: Ignoring 71 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
plot_3D_ternary_cell_markers("Macrophages", Markers.toPlot[2])
##       0%      10%      50%      80%      99% 
## -0.19391 -0.19391 -0.19391  0.66705 11.22766
## Warning: Ignoring 71 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
plot_3D_ternary_cell_markers("Macrophages", Markers.toPlot[3])
##        0%       10%       50%       80%       99% 
## -0.355310 -0.355310  0.831290  2.826760  8.412654
## Warning: Ignoring 71 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels